#!/usr/bin/env python
# _*_coding:utf-8_*_

"""
@Time :    2019/10/24 13:22
@Author:  ThinHeader
@File: serializers.py
@Software: PyCharm
"""
from rest_framework import serializers

from common.tools.money_cast import FloatToIntField
from product.models import Product


class ProductSerializer(serializers.ModelSerializer):
    """
    微砍价序列化类
    """

    price_original = FloatToIntField(
        error_messages={
            'invalid': u'原价应为数字',
        }
    )
    price_discount = FloatToIntField(
        error_messages={
            'invalid': u'底价应为数字',
        }
    )

    class Meta:
        model = Product
        fields = (
            'id', 'shop', 'priority', 'specs', 'title', 'price_original', 'price_discount', 'image', 'shelve', 'desc',
            'status',
            'inventory')
        read_only_fields = ('id', 'shelve')
